package com.itboye.ihomebank.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * Created by Administrator on 2018/8/20 0020.
 */

public class FaceDetectionDBManager {

    FaceDetectionDBHelper mDbHelper;
    SQLiteDatabase db;

    public FaceDetectionDBManager(Context mContext) {
        mDbHelper = new FaceDetectionDBHelper(mContext);
    }

    /**
     * 添加活体检测的url到表里
     *
     * @param url 活体检测url
     * @param isfirst 是否是已经认证成功的
     * @return
     */
    public long addFaceDete(String url,String isfirst) {
        db = mDbHelper.getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.put("url", url);
        cv.put("isfirst", isfirst);

        long num = db.insert("face_detection", null, cv);
        db.close();
        return num;
    }

    /**
     *
     *
     * @return
     */
    public String getFaceDete(String url) {
        db = mDbHelper.getReadableDatabase();
        String isfirst = "否";
        // Cursor mCursor = db.query("hetong", null, "uid=?",
        // new String[] { uid }, null, null, null);
        Cursor mCursor2 = db.rawQuery(
                "select * from face_detection where url=?",
                new String[] {url});
        if (url != null) {
            while (mCursor2.moveToNext()) {
                isfirst = mCursor2.getString(mCursor2.getColumnIndexOrThrow("isfirst"));
            }
            mCursor2.close();
        }
        db.close();
        return isfirst;
    }

    public long deleteFaceDete(String url) {
        db = mDbHelper.getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.put("url", url);
        long num = db.delete("face_detection", "url=?", new String[] {url });
        db.close();
        return num;
    }
}
